//
//  HYBookRoomPlaneWebVC.m
//  Booking
//
//  Created by Duntech on 2018/10/11.
//  Copyright © 2018年 Duntech. All rights reserved.
//

#import "HYBookRoomPlaneWebVC.h"
#import "HYBookingRoomFilterView.h"
#import "HYSeatCellModel.h"
#import "HYDateCityFloorView.h"

@interface HYBookRoomPlaneWebVC () <WKUIDelegate,WKNavigationDelegate,WKScriptMessageHandler>

@property (nonatomic,strong) HYBookingRoomFilterView *filterView;
@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UILabel *avalibleLab;
@property (nonatomic, strong) UILabel *avalibleDesLab;
@property (nonatomic, strong) UILabel *unAvalibleLab;
@property (nonatomic, strong) UILabel *unAvalibleDesLab;

/** webView */
@property (nonatomic,strong)  WKWebView *webView;
@property (nonatomic,copy)    NSString *url;

@property (nonatomic, assign) BOOL isShowSelectView;
@property (nonatomic, strong) HYDateCityFloorView *cityFloorView;



@end

@implementation HYBookRoomPlaneWebVC

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.title = KLocalString(@"bookingRoom");
//    self.url = @"http://smartbooking.ctf.com.cn/vBookingGold//Room/floorplanphone?type=room&office=SZ&building=CTF&floor=12&date=2018-10-11&from=17:30&to=18:30&capacity=0&staffid=Mm44eVBOQkF5QWwwVVNPR0Z4RVFBZzRUQ0IvMVZPMXRFZWZKZVdjYlNsMTZ3SEVNVzB6bDhRPT0=";
//    self.url = @"http://192.168.20.104:8080";
    self.url = @"http://192.168.20.103:9008/static/views/svg/RoomSignage.htm";
    [self setupSubviews];
    [self setupMasonryLayout];
}

- (void)setupSubviews{
    
    [self.view addSubview:self.filterView];
    
    [self.view addSubview:self.topView];
    [self.topView addSubview:self.avalibleLab];
    [self.topView addSubview:self.avalibleDesLab];
    [self.topView addSubview:self.unAvalibleLab];
    [self.topView addSubview:self.unAvalibleDesLab];
    
    [self.view addSubview:self.webView];
    
    
}

- (void)setupMasonryLayout{
    
    [_filterView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.view);
        make.height.mas_equalTo(KTopFilterViewHeight);
    }];
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.filterView.mas_bottom);
        make.left.right.mas_equalTo(self.view);
        make.height.mas_equalTo(36);
    }];
    
    [self.avalibleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.topView.mas_centerY);
        make.left.mas_equalTo(self.topView.mas_left).mas_offset(10);
        make.size.mas_equalTo(CGSizeMake(13, 13));
    }];
    
    [self.avalibleDesLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.topView.mas_centerY);
        make.left.mas_equalTo(self.avalibleLab.mas_right).mas_offset(10);
    }];
    
    [self.unAvalibleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.topView.mas_centerY);
        make.left.mas_equalTo(self.avalibleDesLab.mas_right).mas_offset(10);
        make.size.mas_equalTo(CGSizeMake(13, 13));
    }];
    
    [self.unAvalibleDesLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.topView.mas_centerY);
        make.left.mas_equalTo(self.unAvalibleLab.mas_right).mas_offset(10);
    }];
    
    [_webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.top.equalTo(self.topView.mas_bottom);
    }];
}

#pragma mark - action
- (void)tapFilterViewAction{
    
    if (!self.isShowSelectView) {
        
//        [self.dateCitySelectView showDateCitySelectViewInView:self.view];
    }
    else{
//        [self.dateCitySelectView hideDateCitySelectView];
    }
    self.isShowSelectView = !self.isShowSelectView;
}

- (void)loadMeetingSeatDetailInfoWithSeatId:(NSString *)seatId{
    
    [HYNetRequestHandle getSeatDetailWithSeatID:seatId complection:^(HYBaseNetworkModel *baseModel) {
        HYSeatCellModel *model = [HYSeatCellModel modelWithDictionary:baseModel.result];
//        weakSelf.seatInfoView.seatModel = model;
    }];
}

#pragma mark - WKScriptMessageHandler
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message{
    
    if ([message.name isEqualToString:@""]) {
        
        //判断方法名
        id body = message.body;
        DLog(@"%@",body);
    }
}


#pragma mark - lazyload
- (WKWebView *)webView{
    
    if (!_webView) {
        
        _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - KNAV_HEIGHT)];
        _webView.backgroundColor = [UIColor whiteColor];
        _webView.UIDelegate = self;
        _webView.navigationDelegate = self;
        [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];
        
        //创建WKWebView的配置对象
        WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
        //设置configuration对象的preferences属性的信息
        WKPreferences *preference = [[WKPreferences alloc] init];
        configuration.preferences = preference;
        //是否允许与JS交互，默认YES
        preference.javaScriptEnabled = YES;
        //通过JS与WebView内容交互
        configuration.userContentController = [[WKUserContentController alloc] init];
        [configuration.userContentController addScriptMessageHandler:self name:@"callback"];
    }
    return _webView;
}

- (HYBookingRoomFilterView *)filterView{
    
    if (!_filterView) {
        _filterView = [[HYBookingRoomFilterView alloc] initWithFilterViewMode:FilterViewModePlane];
        [_filterView setHideSwitch];
        _filterView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapFilterViewAction)];
        [_filterView addGestureRecognizer:tapGes];
    }
    return _filterView;
}

-(UIView *)topView{
    if (!_topView) {
        _topView = [UIView new];
        _topView.backgroundColor = KAPP_WHITE_COLOR;
    }
    return _topView;
}

-(UILabel *)avalibleLab{
    if (!_avalibleLab) {
        _avalibleLab = [UILabel new];
        _avalibleLab.backgroundColor = KAPP_Available_COLOR;
    }
    return _avalibleLab;
}

-(UILabel *)avalibleDesLab{
    if (!_avalibleDesLab) {
        _avalibleDesLab = [UILabel new];
        _avalibleDesLab.text = NSLocalizedString(@"available", nil);
        _avalibleDesLab.font = KFont(15);
    }
    return _avalibleDesLab;
}

-(UILabel *)unAvalibleLab{
    if (!_unAvalibleLab) {
        _unAvalibleLab = [UILabel new];
        _unAvalibleLab.backgroundColor = KAPP_7b7b7b_COLOR;
    }
    return _unAvalibleLab;
}

-(UILabel *)unAvalibleDesLab{
    if (!_unAvalibleDesLab) {
        _unAvalibleDesLab = [UILabel new];
        _unAvalibleDesLab.text = NSLocalizedString(@"unavailable", nil);
        _unAvalibleDesLab.font = KFont(15);
    }
    return _unAvalibleDesLab;
}

- (HYDateCityFloorView *)cityFloorView{
    
    if (!_cityFloorView) {
        
        _cityFloorView = [HYDateCityFloorView new];
        _cityFloorView.viewController = self;
    }
    return _cityFloorView;
}

//- (HYDateCitySelectView *)dateCitySelectView{
//
//    if (!_dateCitySelectView) {
//
//        _dateCitySelectView = [HYDateCitySelectView new];
//        _dateCitySelectView.viewController = self;
//        kWeakSelf(weakSelf);
//        _dateCitySelectView.dateCitySearchBlock = ^(NSDate *date, NSString *startTime, NSString *endTime, NSString *cityID, NSString *buildingID, NSString *city, NSString *building) {
//
//            DLog(@"date:%@,startTime:%@,endTime:%@,cityID:%@,buildingID:%@,city:%@,building:%@",date,startTime,endTime,cityID,buildingID,city,building);
//
//            //            weakSelf.selectBuildingID = buildingID;
//            //            weakSelf.selectCityID = cityID;
//            //
//            //
//            //            [HYNetRequestHandle getAvailableMeetingRoomWithPageNo:nil pageSize:nil status:nil city:cityID build:buildingID floor:nil markName:nil Complection:^(NSArray *availableMeetingRoomList) {
//            //                [weakSelf.sectionArray removeAllObjects];
//            //                [weakSelf.dataSetsArray removeAllObjects];
//            //                [availableMeetingRoomList enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//            //
//            //                    HYMeetingRoomModel *model = [HYMeetingRoomModel modelWithDictionary:obj];
//            //                    model.cellIdientifier = @"HYMeetingListCell";
//            //                    model.cellHeight = 140 * WIDTH_MULTIPLE;
//            //                    [weakSelf.sectionArray addObject:model];
//            //                }];
//
//            //            }];
//        };
//    }
//    return _dateCitySelectView;
//}


- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
